find nth ugly number efficiently